/*
 * @Author: gxx
 * @QQ:1278255275
 * @Date: 2021-04-08 16:29:27
 * @Last Modified by: gxx
 * @Last Modified time: 2021-04-08 16:29:27
 * @Description: 
*/

/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    // int ans = INT_MIN;
    int maxPathSum(TreeNode* root) {
        if(root == nullptr) return 0;
        int left = max(0,maxPathSum(root->left));
        int right = max(0,maxPathSum(root->right));
        // ans = max(ans,left+ right + root->val);
        return max(left, right) + root->val;
    }
};

//[1,2,3]  -> 4?
